package com.wizz.trade.template.service.impl;

import com.wizz.trade.template.core.ITemplateHandler;
import com.wizz.trade.template.core.TemplateHandlerFactory;
import com.wizz.trade.template.entity.Template;
import com.wizz.trade.template.mapper.TemplateMapper;
import com.wizz.trade.template.service.TemplateService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Map;

@Service
public class TemplateServiceImpl implements TemplateService {

    @Resource
    public TemplateMapper templateMapper;

    @Resource
    public TemplateHandlerFactory templateHandlerFactory;


    @Override
    public ArrayList<Template> getTemplateMetaInfo(Integer id) {
        return templateMapper.getTemplateMetaInfo(id);

    }

    @Override
    public Template getTemplateDetailsByTemplateId(Integer id) {
        ITemplateHandler templateGenerator = templateHandlerFactory.getTemplateGenerator(id);
        return templateGenerator.doGenerate();
    }

    @Override
    public ArrayList<String> getClausesByTemplateId(Integer id) {
        return templateMapper.getClausesByTemplateId(id);

    }

    @Override
    public void export(HttpServletResponse resp, Integer id, Map<String, Object> params) {
        ITemplateHandler templateGenerator = templateHandlerFactory.getTemplateGenerator(id);
        templateGenerator.doExport(resp,params);
    }


}
